﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using X.Entity;

namespace X.DataFactory
{
    public interface IProduct
    {
        int Create(ProductInfo productInfo);
        bool Delete(int productId);
        ProductInfo GetProduct(int productId);
        ProductInfo GetProduct(string productName);
        IList<ProductInfo> GetAllList();
        IList<ProductInfo> GetList();
        IList<ProductInfo> GetList(int topCount);
        IList<ProductInfo> GetHotList(int topCount);    //热销
        IList<ProductInfo> GetRecList(int topCount);    //推荐
        IList<ProductInfo> GetListByCategoryName(string categoryName);
        IList<ProductInfo> GetListByCategoryId(int categoryId);
        IList<ProductInfo> GetListByPrice(decimal lowPrice, decimal hightPrice);

        bool Update(ProductInfo productInfo);
        IList<ProductInfo> Search(string keyword);
        void UploadImage(int productId, IList<string> list);
        void DeleteImage(int imageId);
        IList<string> GetImagesList(int productId);

        IList<PriceInfo> GetPriceList();
        bool CreatePrice(PriceInfo priceInfo);
        bool UpdatePrice(PriceInfo priceInfo);
        bool DeletePrice(int id);
        PriceInfo GetPriceInfo(int id);

        IList<TagInfo> GetTagList();
        IList<TagInfo> GetAllTagList();
        TagInfo GetTagInfo(int tagId);
        bool UpdateTag(TagInfo tagInfo);
    }

    public interface IProductCategory
    {
        bool Create(ProductCategoryInfo category);
        bool Delete(int categoryId);
        ProductCategoryInfo GetCategory(int categoryId);
        ProductCategoryInfo GetCategory(string categoryName);
        IList<ProductCategoryInfo> GetList();
        IList<ProductCategoryInfo> GetCategoryList();
        IList<ProductCategoryInfo> GetNavList();
        bool Update(ProductCategoryInfo categoryInfo);
        int GetProductCount(int categoryId);
    }

    public sealed partial class DataAccess
    {
        public static IProduct CreateProduct()
        {
            string typeName = path + ".Product";

            return (IProduct)Assembly.Load(path).CreateInstance(typeName);
        }

        public static IProductCategory CreateProductCategory()
        {
            string typeName = path + ".ProductCategory";

            return (IProductCategory)Assembly.Load(path).CreateInstance(typeName);
        }
    }
}
